import time

filea = open("file.txt", "r", encoding="utf-8") # <_io.TextIOWrapper name='file.txt' mode='r' encoding='utf-8'>
print(filea)
# mode 模式r 只读  w写入  a 追加
filess = filea.read(10)  #读取10个字符，不传则读取所有
print(filess)
# file2 = filea.readline() # 读取一行
file2 = filea.readlines() # 按行读取整个文件 ['3\n', 'sdf\n', 'sdf\n', '\n', 'sdfsdf\n', 'sadfsdf']
print(file2) # 这里文件的指针是接着读的 \n 换行
filessss = filea.read() # 指针到文档最后了，挺特殊的
print('接着读读不到了吧：',filessss)
filea.close()
filea3 = open("file.txt", "r", encoding="utf-8")

for item in filea3:
    print('for 循环默认每次读一行',item)


filea3.close()
# with open  as  自动关闭文件
with open('file.txt', 'r', encoding='utf-8') as f3:
    for item in f3:
        print(item)